<%@page import="com.card.user.UserCurrency.CurrencyKind"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@page import="com.card.user.*"%>
<%@include file="m_head.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
<%
	String id = request.getParameter("id");
	if(id == null) {
		id = "";
	}
	User user = null;

	List<User> users = null;
	if(id == null || "".equals(id)) {
		users = UserUtils.getUsers(admin.getId());
	} else {
		user = UserUtils.getUserByPrimaryKey(id);
	}
%>
<body>
	<div data-role="page" id="demo-page">
		<div data-role="header">
	        <h1>我的房卡数:<%=admin.getGold() %></h1>
	        <h1>我的权限:<%=admin.getGroup()%></h1>
	        <a href="#myPanel" data-icon="bars" data-shadow="false" data-iconshadow="false">菜单</a>
	    </div>
		<div role="main" class="ui-content">
			<script type="text/javascript">
			function search_agent()
			{
				var search = document.getElementById("search");
				var value = search.value;
				location.href="m_agent_info.jsp?id="+value;
			}
			function czgold(i)
			{
				var gold = document.getElementById("gold"+i).value;
				var search = document.getElementById("searchuser"+i);
				var value = search.value;
				$.ajax({
			   		type:"post",//请求方式
			  		url:"/GameServer/doActionPhone",//发送请求地址
			   		data:{action:'sellerGold',name:value,gold:gold},
			  	 	success:function(data,textStatus){
			  	 		var json = JSON.parse(data);
			  	 		var ok = json.ok;
			  	 		alert(json.msg);
			  	 		if(ok == 1) {
			  	 			window.location.reload();
			  	 		}
			   		}
			   	}); 
			}
			function jsgold(i)
			{
				var gold = document.getElementById("gold"+i).value;
				var search = document.getElementById("searchuser"+i);
				var value = search.value;
				$.ajax({
			   		type:"post",//请求方式
			  		url:"/GameServer/doActionPhone",//发送请求地址
			   		data:{action:'reduceGold',name:value,gold:gold},
			  	 	success:function(data,textStatus){
			  	 		var json = JSON.parse(data);
			  	 		var ok = json.ok;
			  	 		alert(json.msg);
			  	 		if(ok == 1) {
			  	 			window.location.reload();
			  	 		}
			   		}
			   	}); 
			}
		</script>
		<input type="search" value="<%=id %>" name="id" id="search" placeholder="玩家id"><br>
		<input type="button" onclick="search_agent()" value="搜索"><br>
	    <%
	    	if(user != null) {
	    %>
	    	<label for="text" data-theme="e">ID:<%=user.getPrimaryKey() %></label> <br>
			<label for="text" data-theme="e">昵称:<%=user.userExtra().getNickName() %></label> <br>
			<label for="text" data-theme="e">俱乐部ID:<%=user.getJulebuid() %></label> <br>
			<label for="text" data-theme="e">当前房卡数:<%=user.userCurrency().get(CurrencyKind.Diamonds) %></label> <br>
			
	      	<input type="text" name="gold" id="gold" placeholder="充值数" value="0"> 
	      	<input type="hidden" name="searchuser" id="searchuser" placeholder="用户id" value="<%=user.getPrimaryKey() %>" > 
			<input type="button" style="background-color: #820000" onclick="czgold(<%=""%>)" value="充值">
			 
			<c:if test="${admin.getGroup() == 1}">
			<input type="button"  style="background-color: #820000" onclick="jsgold(<%=""%>)" value="减少"></c:if>
	    <% 
	    	}
	    %>
	    <table class="table table-bordered">
	    <%
	    	if(users != null) {
	    		for ( int i=0;i<users.size(); i++) {
		    		User user3 = users.get(i);
	    %>
			<tr>
		      <td><label for="text" data-theme="e">ID:<%=user3.getPrimaryKey() %></label> </td>
		      <td><label for="text" data-theme="e">昵称:<%=user3.userExtra().getNickName() %></label></td>
		      <td><label for="text" data-theme="e">俱乐部ID:<%=user3.getJulebuid() %></label></td>
		      <td><label for="text" data-theme="e">当前房卡数:<%=user3.userCurrency().get(CurrencyKind.Diamonds) %></label> </td>
			
	      	<td><input type="text" name="gold" id="gold<%=i%>" placeholder="充值数" value="0"> </td>
	      	<td><input type="hidden" name="searchuser" id="searchuser<%=i%>" placeholder="用户id" value="<%=user3.getPrimaryKey() %>" > </td>
			<td><input type="button" style="background-color: #820000" onclick="czgold(<%=i%>)" value="充值"></td>
			<c:if test="${admin.getGroup() == 1}">
			<td><input type="button"  style="background-color: #820000" onclick="jsgold(<%=i%>)" value="减少"></td>
			</c:if>
			</tr>
	    <% 
	    		}
	    	}
	    %>
	    </table>
	    <br><br>
		
		</div>
		
		<%@include file="m_order.jsp"%>
	</div>
</body>
</html>